package utils;

import java.lang.instrument.Instrumentation;

public class TimeUtils {
    private boolean flag;//运行标志,默认为true,当改成false时停止运行

    private int afterSec;//剩余时间
    public TimeUtils(boolean flag) {
        this.flag = flag;
    }

    public int getAfterSec() {
        return afterSec;
    }

    public void setAfterSec(int afterSec) {
        this.afterSec = afterSec;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public  void mockRun(int sec){
        //模拟运行sec秒
        long start = System.currentTimeMillis();
        
        while (this.flag==true&&System.currentTimeMillis()-start<=(sec*1000)){

        }
        if(this.flag==false&&System.currentTimeMillis()-start<=(sec*1000)){
            long end=System.currentTimeMillis()-start;
            long l = sec * 1000 - end;//剩余时间，单位毫秒
            l/=1000;
            this.afterSec=(int)l;//转化为Int 剩余值
        }
    }

    public static void main(String[] args) {

    }
}
